package com.xzjt.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.xzjt.entity.MenuTree;
import com.xzjt.entity.SysMenu;
import com.xzjt.service.SysMenuService;
import com.xzjt.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName: SysMenuController
 * @Author: yuandong
 * @Date 2021/10/11 9:15
 * 菜单Controller
 */
@RestController
@RequestMapping("/sys")
public class SysMenuController {

    @Autowired
    private SysMenuService sysMenuService;

    /**
     * 查询所有菜单(并构建树形结构)
     * @return
     */
    @GetMapping("/menuTree/{userId}")
    public R getMenuTree(@PathVariable Integer userId){
        List<SysMenu> menus=null;

        if(userId.equals(1)){
            menus =  this.sysMenuService.selectList();
        }else{
            //此处需要进行user,menu,user_menu三个表关联查询
            menus = this.sysMenuService.selectList();
        }

        MenuTree menuTree=new MenuTree(menus);
        List<SysMenu> menuList = menuTree.builTree();
        return R.ok(menuList);
    }

    /**
     * 查询用户对应的菜单
     * @param userId
     * @return
     */
    public R getMenuTreeByUser(Integer userId){
        return R.ok();
    }


}
